package com.winbaoxian.testng.platform.controller;

import com.winbaoxian.testng.platform.model.common.JsonResult;
import com.winbaoxian.testng.platform.model.common.Pagination;
import com.winbaoxian.testng.platform.model.common.PaginationDTO;
import com.winbaoxian.testng.platform.model.dto.PlatformTestReportDTO;
import com.winbaoxian.testng.platform.model.dto.TestReportQueryParams;
import com.winbaoxian.testng.platform.service.ReportService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author dongxuanliang252
 * @date 2019-03-20 11:59
 */
@RestController
@RequestMapping(value = "/testReport")
public class ReportController {

    @Resource
    private ReportService reportService;

    /**
     * @api {GET} /testReport/page 分页获取测试报告
     * @apiVersion 1.0.0
     * @apiGroup ReportController
     * @apiName page
     * @apiParam (请求参数) {Number} projectId 项目ID
     * @apiParam (请求参数) {Number} moduleId 模块ID
     * @apiParam (请求参数) {Number} testCasesId 测试任务ID
     * @apiParam (请求参数) {Number} executorUid 执行人ID
     * @apiParam (请求参数) {Number} startTime 开始时间
     * @apiParam (请求参数) {Number} endTime 结束时间
     * @apiParam (请求参数) {Number} triggerMode 触发方式
     * @apiParam (请求参数) {Number} runState 运行状态
     * @apiParam (请求参数) {Number} pageNum 第几页
     * @apiParam (请求参数) {Number} pageSize 每页数量
     * @apiParamExample 请求参数示例
     * testCasesId=3704&executorUid=8310&pageSize=8129&startTime=5848&endTime=1590&moduleId=4602&projectId=5770&triggerMode=7739&runState=7401&pageNum=3724
     * @apiSuccess (响应结果) {Number} code 200 成功， 400 失败
     * @apiSuccess (响应结果) {String} msg 提示信息
     * @apiSuccess (响应结果) {Object} data 数据
     * @apiSuccess (响应结果) {Array} data.list 列表
     * @apiSuccess (响应结果) {String} data.list.executorName 执行人名字
     * @apiSuccess (响应结果) {String} data.list.reportUrl 测试报告地址
     * @apiSuccess (响应结果) {String} data.list.projectNames 项目名称
     * @apiSuccess (响应结果) {String} data.list.testCasesNames 测试任务名称
     * @apiSuccess (响应结果) {Number} data.list.id
     * @apiSuccess (响应结果) {Number} data.list.createTime 创建时间
     * @apiSuccess (响应结果) {Number} data.list.updateTime 更新时间
     * @apiSuccess (响应结果) {Number} data.list.executorUid 执行人UID
     * @apiSuccess (响应结果) {String} data.list.reportUuid 报告唯一UID
     * @apiSuccess (响应结果) {Number} data.list.startTime 开始时间
     * @apiSuccess (响应结果) {Number} data.list.endTime 结束时间
     * @apiSuccess (响应结果) {Number} data.list.duration 花费的时间(单位毫秒)
     * @apiSuccess (响应结果) {Number} data.list.totalCount 总数
     * @apiSuccess (响应结果) {Number} data.list.successCount 成功数
     * @apiSuccess (响应结果) {Number} data.list.failCount 失败数
     * @apiSuccess (响应结果) {Number} data.list.triggerMode 触发方式
     * @apiSuccess (响应结果) {Number} data.list.runState 运行状态
     * @apiSuccess (响应结果) {Boolean} data.list.deleted 是否删除，1:删除， 0:有效
     * @apiSuccess (响应结果) {Number} data.pageNum 第几页
     * @apiSuccess (响应结果) {Number} data.pageSize 每页数量
     * @apiSuccess (响应结果) {Number} data.totalRow 总数
     * @apiSuccess (响应结果) {Number} data.totalPage 总页数
     * @apiSuccess (响应结果) {String} data.orderProperty 排序字段
     * @apiSuccess (响应结果) {String} data.orderDirection 排序方式, DESC 降序;ASC 升序
     * @apiSuccessExample 响应结果示例
     * {"msg":"7sBJwxrRT8","code":1201,"data":{"totalRow":5514,"totalPage":6285,"pageSize":7629,"orderDirection":"SJOExsNj","list":[{"executorUid":96,"failCount":8260,"projectNames":"hqWThHF","updateTime":1355928329366,"reportUrl":"rZFJWOaL","totalCount":9089,"testCasesNames":"nXd4zLQ0","reportUuid":"DQ","duration":2380,"executorName":"F","deleted":false,"createTime":1078659271318,"successCount":6569,"startTime":1674647236122,"id":9250,"endTime":1890508427395,"triggerMode":8371,"runState":1354}],"pageNum":5662,"orderProperty":"GoLGbYmU"}}
     */
    @GetMapping(value = "page")
    public JsonResult<PaginationDTO<PlatformTestReportDTO>> page(TestReportQueryParams params, Pagination pagination) {
        return JsonResult.createSuccessResult(reportService.page(params, pagination));
    }


}
